package com.javablog.repository;

import com.javablog.model.Article;
import com.javablog.model.Comment;
import com.javablog.model.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {
    
    Page<Comment> findByArticle(Article article, Pageable pageable);
    
    Page<Comment> findByUser(User user, Pageable pageable);
    
    Page<Comment> findByParentIsNull(Pageable pageable);
    
    List<Comment> findByParent(Comment parent);
    
    @Query("SELECT c FROM Comment c ORDER BY c.createdAt DESC")
    Page<Comment> findLatest(Pageable pageable);
    
    @Query("SELECT c FROM Comment c ORDER BY c.likes DESC")
    Page<Comment> findMostLiked(Pageable pageable);
} 